package com.example.arithmeticleetcode.leetcode.dec;


import java.util.Arrays;
import java.util.Stack;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-16 09:58
 **/
public class Demo14 {

    int index ;

    public Demo14() {
        index = 0;
    }

    public static void main(String[] args) {
//        int[] ints = new int[]{1, 2, 3};
//        int index= 0;
//        ints[index++] = 2;
//        System.out.println(Arrays.toString(ints));
//        ints[--index] = 0;
//        System.out.println(Arrays.toString(ints));


    }

}

class CustomStack {

    private Stack<Integer> stack;
    private int curIndex;
    private int[] arr;


    public CustomStack(int maxSize) {
        stack = new Stack<>();
        arr = new int[maxSize];
        curIndex = 0;
    }

    public void push(int x) {
        if (curIndex >= arr.length) return;
        stack.push(x);
        arr[curIndex++] = x;

    }

    public int pop() {
        if (stack.isEmpty()) return -1;
        arr[--curIndex] = 0;
        return stack.pop();
    }


    public void increment(int k, int val) {
        if (stack.isEmpty()) return;
        stack.clear();
        for (int i = 0; i < arr.length; i++) {
            if (k > 0) {
                stack.push(arr[i] + val);
                k--;
            } else stack.push(arr[i]);
        }
    }

    public void increment2(int k, int val) {
        if (stack.isEmpty()) return;
        int[] ints = new int[stack.size()];
        int index = 0;
        while (!stack.isEmpty()) {
            ints[index++] = stack.pop();
        }
        for (int i = ints.length - 1; i >= 0; i--) {
            if (k > 0) {
                stack.push(ints[i] + val);
                k--;
            }
            stack.push(ints[i]);
        }
    }
}
